package com.hubstc.book_borrow.mapper;

import com.hubstc.book_borrow.pojo.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookMapper {

    //添加图书
    @Insert("insert into book (bookId,bookCategory, bookName, author, publisher, publishTime, price, stock, borrowNum) " +
            "values (#{bookId},#{bookCategory},#{bookName},#{author},#{publisher},#{publishTime},#{price},#{stock},#{borrowNum});")
    void addBook(Book book);


    //分页查询
    @Select("SELECT * FROM book " +
            "WHERE bookCategory LIKE IFNULL(CONCAT('%', #{bookCategory}, '%'), '%') " +
            "AND bookName LIKE IFNULL(CONCAT('%', #{bookName}, '%'), '%')")
    List<Book> list(String bookCategory,String bookName);
    
    //更新图书信息
    @Update("update book " +
            "set bookCategory = #{bookCategory},bookName=#{bookName},author=#{author},publisher=#{publisher},publishTime=#{publishTime},price=#{price},stock=#{stock},borrowNum=#{borrowNum} "+
            "where bookId=#{bookId};")
    void updateBook(Book book);

    @Delete("delete from book where bookId=#{bookId}")
    void deleteBook(String bookId);



}
